package com.ikas.ai.server.module.appraise.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikas.ai.server.error.BusinessException;
import com.ikas.ai.server.module.appraise.dao.AppraiseConstantDAO;
import com.ikas.ai.server.module.appraise.model.AppraiseConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service("tAppraiseConstantService")
public class AppraiseConstantService extends ServiceImpl<AppraiseConstantDAO, AppraiseConstant> {

    @Autowired
    private AppraiseConstantDAO appraiseConstantDAO;

    @Override
    public boolean save(AppraiseConstant entity) {
        LambdaQueryWrapper<AppraiseConstant> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AppraiseConstant::getMark, entity.getMark());
        AppraiseConstant existConstant = getOne(lambdaQueryWrapper);
        if (Objects.nonNull(existConstant)) {
            throw new BusinessException("常量已存在");
        }
        return super.save(entity);
    }

    public Integer delete(Long id) {
        return appraiseConstantDAO.deleteById(id);
    }
}